package Homework.cms.servlet;

import Homework.cms.user.Member;
import Homework.cms.user.MemberService;
import com.xcms.test.news.News;
import com.xcms.test.news.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.sql.Date;

public class AddnewsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");     //告诉它当前文档的编码
        response.setHeader("Content-Type","text/html;utf-8");    //告诉浏览器文档类型
        String title=request.getParameter("title2");
        String url=request.getParameter("content2");

        PrintWriter out=response.getWriter();   //获取一个打印流，向网页输出打印

        News news=new News();
        news.setTitle(title);
        news.setUrl(url);
        if(NewsDao.insert(news)){
            out.println("添加成功！");
            response.setHeader("Refresh","3;url=http://localhost:8080/webtest/Homework/manage/news?action=page2&currPage=1");
        }
        else {
            out.println("添加失败！");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
